<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>添加需求信息</title>
  <jsp:include page="../../common/common_resources.jsp"/>
  <style>
    .cont {
      padding: 10px 20px;
    }
  </style>
</head>
<body>
<div class="cont">
  <form class="layui-form layui-form-pane" lay-filter="addDialog">
    <div class="layui-form-item">
      <label class="layui-form-label">需求标题</label>
      <div class="layui-input-block">
        <input type="text" name="title" placeholder="请输入需求标题"
               class="layui-input" lay-verify="required">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">学习的课程</label>
      <div class="layui-input-block">
        <input type="text" name="courseName" placeholder="请输入要学习的课程名"
               class="layui-input" lay-verify="required">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">需求描述</label>
      <div class="layui-input-block">
        <textarea name="detailDesc" placeholder="请输入需求描述"
                  rows="6"
                  class="layui-textarea">
        </textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <!--lay-submit绑定触发提交的元素,无需填写值-->
        <button type="submit" class="layui-btn" lay-submit lay-filter="addSubmit">确认添加</button>
      </div>
    </div>
  </form>
</div>
<script>
  layui.use(['jquery', 'form'], function ($,form) {
    // 添加书籍类型表单事件
    form.on('submit(addSubmit)', function (data) {
      $.ajax({
        url: '<%=request.getContextPath() %>/studentDemand/add',
        method: 'post',
        data: data.field,//当前容器的全部表单字段，名值对形式：{name: value}
        success: function (data) {
          if (data.success) {
            parent.layui.table.reload("tb",{
              page:{
                curr:1
              }
            });
            // window.name:layui-layer-iframe1 会被layui改写
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
          } else {
            layer.msg(data.errMsg);
          }
        }
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
  });
</script>
</body>
</html>
